;; lenovo ideapad 100s (chromebook) 的配置


(use-modules
 (gnu)
 (gnu packages)
 (gnu packages bash)
 (gnu packages vpn)
 (gnu packages xorg)
 (gnu packages suckless)
 (luhux packages linux-nonfree)
 
 (gnu services base)
 (gnu services networking)
 (gnu services ssh)
 (gnu services xorg)
 (gnu services desktop)
 (gnu services pm)
 (gnu services sound)
 (gnu services sddm)
 (gnu services sysctl)
 (luhux services compat)
 (luhux services vpn)
 )



(operating-system
 (host-name "chromebook")  
 (timezone "Hongkong")
 (locale "en_US.utf8")
 
 ;; 内核 
 (kernel linux-5.7.15)

 ;; 内核参数
 (kernel-arguments 
  (append
   (list
    ;; ZSWAP设置    
    "zswap.enabled=1"
    "zswap.compressor=lz4"
    "zswap.zpool=z3fold"
    ;; 关机键是摆设，所以panic自动重启
    "panic=120"
    ;; 等待文件系统就绪
    "rootwait"
    )
   %default-kernel-arguments
   )
  )


 ;; 内核附加模块
 ;; < 5.7的linux内核不需要树外的wireguard模块
; (kernel-loadable-modules (list wireguard-linux-compat))

 ;; initrd 模块
 (initrd-modules
   (list
    ;; EMMC 需要的模块    
    "sdhci-acpi"
    "mmc_block"
    )
  )

 ;; 固件
 (firmware (list linux-firmware-nonfree-20200619))

 ;; 引导
 (bootloader (bootloader-configuration
	      (bootloader grub-efi-bootloader)
	      (target "/boot/efi")))
 
 ;; 文件系统
 (file-systems (append (list (file-system
			      (device "/dev/mmcblk0p2")
			      (mount-point "/")
			      (type "btrfs")
			      (options "compress-force=zstd:15")
			      (check? #t)
			      ) ;; 可轻松重现的数据，使用实验性文件系统
			     (file-system
			      (device "/dev/mmcblk0p3")
			      (mount-point "/home")
			      (type "ext4")
			      (check? #t)
			      )  ;; 为了数据安全，重要的难以重现的数据使用可靠的文件系统
			     (file-system
			      (device "/dev/mmcblk0p1")
			      (mount-point "/boot")
			      (type "vfat")
			      (check? #t)
			      )  ;; boot & efi
			     )
		       %base-file-systems))
 ;; swapfile
 (swap-devices '("/var/swapfiles/0"
		 "/var/swapfiles/1"))

 ;; 账户
 (users (cons (user-account
	       (name "chromebook")
	       (comment "user")
	       (group "users")

	       (supplementary-groups '("wheel"
				       "audio" "video")))
	      %base-user-accounts))

 ;; 全局安装的包
 (packages
  (map
   specification->package
   (list
    ;; shell
    "bash"
    ;; 基础命令
    "coreutils"
    "findutils"
    "grep"
    "sed"
    "diffutils"
    "patch"
    "gawk"
    "util-linux-with-udev"

    ;; 归档
    "tar"

    ;; 压缩
    "gzip"
    "xz"
    "bzip2"

    ;; Linux 模块
    "kmod"

    ;; udev
    "eudev"
    
    ;; 用户管理
    "shadow"

    ;; 进程
    "psmisc"
    "procps"

    ;; 编辑器
    "vim"

    ;; 终端
    "kbd"

    ;; 分页
    "less"

    ;; 网络
    "inetutils"
    "isc-dhcp"
    "iproute2"
    "net-tools"
    
    ;; 终端复用器
    "tmux"

    ;; ssl证书
    "nss-certs"

    ;; bash 补全
    "bash-completion"

    ;; 无线网络
    "wireless-tools"

    ;; 蓝牙
    "bluez"

    ;; 声音
    "alsa-utils"

    ;; wm
    "cwm"

    ;; 文件系统
    "e2fsprogs"
    "btrfs-progs"
    "dosfstools"
    "efibootmgr" ;; efivars

    ;; Wireguard VPN
    "wireguard-tools"

    ;; CPU 性能调整
    "cpupower"
    )
   )
  )

 ;; setuid
 (setuid-programs (append
		   (list
		    (file-append slock "/bin/slock")
		    )
		   %setuid-programs
		   )
		  )

 ;; 服务
 (services
  (list
   ;; 脚本兼容
   (service special-files-service-type
	    `(("/bin/sh" ,(file-append bash "/bin/sh"))
	      ("/usr/bin/env" ,(file-append coreutils "/bin/env"))))

   ;; tty 登录
   (service login-service-type)
   (service virtual-terminal-service-type)
   (service agetty-service-type (agetty-configuration
				 (extra-options '("-L"))
				 (term "vt100")
				 (tty #f)))
   (service mingetty-service-type (mingetty-configuration
				   (tty "tty1")))
   (service mingetty-service-type (mingetty-configuration
				   (tty "tty2")))
   (service mingetty-service-type (mingetty-configuration
				   (tty "tty3")))
   (service mingetty-service-type (mingetty-configuration
				   (tty "tty4")))
   (service mingetty-service-type (mingetty-configuration
				   (tty "tty5")))
   (service mingetty-service-type (mingetty-configuration
				   (tty "tty6")))
   
   ;; 随机数设备
   (service urandom-seed-service-type)

   ;; guix 服务
   (service guix-service-type
	    (guix-configuration
	     (substitute-urls (list
			       "https://mirror.guix.org.cn"
			       "https://ci.guix.gnu.org"
			       )
			      )
	     )
	    )

   ;; nscd 服务
   (service nscd-service-type)

   ;; udev
   (service udev-service-type)

   ;; log 记录服务
   (syslog-service)


   ;; 网络
   (service static-networking-service-type
	    (list (static-networking (interface "lo")
				     (ip "127.0.0.1")
				     (requirement '())
				     (provision '(loopback)))))

   (service dhcp-client-service-type)

   ;; ssh服务
   (service openssh-service-type)

   ;; 无线网络
   (service wpa-supplicant-service-type
	    (wpa-supplicant-configuration
	     (interface "wlp1s0")
	     (config-file "/etc/wpa_supplicant.conf")
	     )
	    )

   ;; ntp
   (service openntpd-service-type)

   ;; nftables
   (service nftables-service-type
	    (nftables-configuration
	     (ruleset "/etc/nftables.rule")
	     )
	    )
   
   ;; sddm  登录管理器
   (service sddm-service-type
	    (sddm-configuration
	     (display-server "x11")
	     (numlock "off")
	     (xorg-configuration
	      (xorg-configuration
	       (modules   ;; 驱动
		(list
		 xf86-video-intel
		 xf86-input-libinput
		 xf86-input-keyboard
		 xf86-input-mouse
		 )
		)
	       (drivers  ;; 图形卡驱动
		(list
		 "intel"
		 )
		)
	       )
	      )
	     )
	    )
   
   ;; guix publish服务
   (service guix-publish-service-type
	    (guix-publish-configuration
	     (port 8181)
	     (host "0.0.0.0")
	     (compression '(("lzip" 9)))
	     (cache "/var/cache/guix/publish")
	     (workers 2)
	     (ttl 86400) ; 保留一天
	     )
	    )

   (service sysctl-service-type
	    (sysctl-configuration
	     (settings '(
			 ;; 流量轉發
			 ("net.ipv4.ip_forward" . "1")

			 ;; BBR
			 ("net.core.default_qdisc" . "fq")
			 ("net.ipv4.tcp_congestion_control" . "bbr")

			 ;; 禁用特权端口
			 ("net.ipv4.ip_unprivileged_port_start" . "0")
			 )
		       )
	     )
	    )

   

   ;; Alsa
   (service alsa-service-type)


   ;; 蓝牙
   (bluetooth-service)

   ;; rc.local compat
   (service rclocal-service-type
	    (rclocal-configuration
	     (script "/etc/rc.local")))

   ;; Wireguard VPN (wg-quick)
   (service wireguard-quick-service-type
	    (wireguard-quick-configuration
	     (interface "tencent")))

   )
  )
 )
